﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;                 
using System.Data.SqlClient;

using System.Text;


namespace finalexam
{
    public partial class Register : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            this.Title = "欢迎来到学生信息管理系统";
        }

        protected void btnRegister_Click(object sender, EventArgs e)
        {
            string strCn = "server=pc.hstc.cn;database=dhd2014112134;uid=2014112134;pwd=19951124";
            SqlConnection cn = new SqlConnection(strCn);

            try
            {
                cn.Open();
                string strGender = Request.QueryString["Gender"];
                if (RadioButton1.Checked)
                {
                    strGender = "男";
                }
                else
                {
                    strGender = "女";
                }

                this.Label10.Text = strGender;

                StringBuilder SqlStringBuilder = new StringBuilder(1024);
                SqlStringBuilder.Append("INSERT INTO login ");
                SqlStringBuilder.Append("                (UserName, Password,Name,Gender ,RegisterTime) ");
                SqlStringBuilder.Append("VALUES   (@UserName,@Password,@Name,@Gender,@RegisterTime) ");

                string strSql = SqlStringBuilder.ToString();


                SqlCommand cmd = new SqlCommand(strSql, cn);
                SqlParameter pmsUserName = new SqlParameter("@UserName", this.txtNo.Text);
                SqlParameter pmsPassword = new SqlParameter("@Password", this.txtPwd.Text);
                SqlParameter pmsName = new SqlParameter("@Name", this.txtName.Text);
                SqlParameter pmsGender = new SqlParameter("@Gender", this.Label10.Text);
                SqlParameter pmsRegisterTime = new SqlParameter("@RegisterTime", this.DropDownList1.Text + this.DropDownList2.Text + this.DropDownList3.Text);


                cmd.Parameters.Add(pmsUserName);
                cmd.Parameters.Add(pmsPassword);
                cmd.Parameters.Add(pmsName);
                cmd.Parameters.Add(pmsGender);
                cmd.Parameters.Add(pmsRegisterTime);

                int iUpd = cmd.ExecuteNonQuery();
                if (iUpd < 1)
                {
                    this.Label10.Text = "注册失败！";
                }
                else
                {
                    this.Label10.Text = "您已成功注册!";
                    this.Label11.Text = "用户名是：" + this.txtNo.Text;
                    this.Label12.Text = "密码是：" + this.txtPwd.Text;
                    this.Label13.Text = "注册时间为：" + this.DropDownList1.Text + this.DropDownList2.Text + this.DropDownList3.Text;

                }
            }
            catch (Exception ex)
            {
                this.Label10.Text = ex.Message;
            }
            finally
            {
                cn.Close();
            }
        }

    }
}